home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / tcpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-07  |  1.5 KB  |  73 lines

  1. #include <conio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "tcp.h"
  7. #include "ip.h"
  8. #include "trace.h"
  9.  
  10. /* Dump a TCP segment header. Assumed to be in network byte order */
  11. void
  12. tcp_dump(fp,bpp,source,dest,check)
  13. FILE *fp;
  14. struct mbuf **bpp;
  15. int32 source,dest;    /* IP source and dest addresses */
  16. int check;            /* 0 if checksum test is to be bypassed */
  17. {
  18.     struct tcp seg;
  19.     struct pseudo_header ph;
  20.     int16 csum, dlen;
  21.  
  22.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  23.         return;
  24.  
  25.     /* Verify checksum */
  26.     ph.source = source;
  27.     ph.dest = dest;
  28.     ph.protocol = TCP_PTCL;
  29.     ph.length = len_p(*bpp);
  30.  
  31.     csum = (check == 1) ? cksum(&ph,*bpp,ph.length) : 0;
  32.  
  33.     ntohtcp(&seg,bpp);
  34.  
  35.     textattr(YELLOW);
  36.     trprintf(fp,"TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
  37.  
  38.     if(seg.flags.ack)
  39.         trprintf(fp," Ack x%lx",seg.ack);
  40.     if(seg.flags.congest)
  41.         trprintf(fp," CE");
  42.     if(seg.flags.urg)
  43.         trprintf(fp," URG");
  44.     if(seg.flags.ack)
  45.         trprintf(fp," ACK");
  46.     if(seg.flags.psh)
  47.         trprintf(fp," PSH");
  48.     if(seg.flags.rst)
  49.         trprintf(fp," RST");
  50.     if(seg.flags.syn)
  51.         trprintf(fp," SYN");
  52.     if(seg.flags.fin)
  53.         trprintf(fp," FIN");
  54.  
  55.     trprintf(fp," Wnd %u",seg.wnd);
  56.  
  57.     if(seg.flags.urg)
  58.         trprintf(fp," UP x%x",seg.up);
  59.  
  60.     /* Print options, if any */
  61.     if(seg.mss)
  62.         trprintf(fp," MSS %u",seg.mss);
  63.  
  64.     if((dlen = len_p(*bpp)) > 0)
  65.         trprintf(fp," Data %u",dlen);
  66.  
  67.     if(csum)
  68.         trprintf(fp," CHECKSUM ERROR (%u)",csum);
  69.  
  70.     trprintf(fp,"\n");
  71. }
  72.  
  73.